import ajax from '../utils/axios';

// 用户模块
export async function login(params) {
  // interface params {
    //  password: string;
    // username: string;
  // }
  const res = await ajax.post(`/user/login`,  params );
  return res.data.data;
}

export async function getUserInfo() {
  const res = await ajax.get(`/user`);
  return res.data.data;
}

export async function editUserInfo(params) {
  const res = await ajax.put(`/user`,params);
  return res.data.data;
}

export async function editPwd(params) {
  const res = await ajax.post(`/user/modify_passwd`, params);
  return res.data.data;
}

// export async function updateAvatar(params) {
//   // params:{avatar: file}
//   const res = await ajax.post(`/user/modify_passwd`, params);
//   return res.data.data;
// }

export async function editAvatar(params){
  const form = new FormData();
  form.append('avatar', params.file);
  const res=await ajax.post(`/user/avatar`,form);
  return res.data.data;
}


// 首页
export async function getCount() {
  const res = await ajax.get(`/overview/count`);
  return res.data.data;
}

// 查询首页今日销售详情
export async function getSellToday() {
  const res = await ajax.get(`/overview/sell_info_today`);
  return res.data.data;
}


export async function getSellWeek() {
  const res = await ajax.get(`/overview/sell_info_week?mock=1`);
  return res.data.data;
}

export async function getSellMonth() {
  const res = await ajax.get(`/overview/sell_info_month?mock=1`);
  return res.data.data;
}

// 查询库存告警
export async function inventoryAlarm(num) {
  const res = await ajax.get(`/overview/inventory_alarm?num=${num}`);
  return res.data.data;
}


export async function proportion(type) {
  const res = await ajax.get(`/overview/proportion?goods_type=${goods_type}`);
  return res.data.data;
}


export async function getBank() {
  const res = await ajax.get(`/supplier/bank_types`);
  return res.data.data;
}

